package com.example.leo.mycharmingstudent.project.maintabfragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.leo.mycharmingstudent.R;
import com.example.leo.mycharmingstudent.project.MainActivity;

/**
 * Created by Leo on 2020/9/28.
 */

public class MineFragment extends Fragment {

    private TextView tvName;

    public static MineFragment newInstance(String name) {
        MineFragment mineFragment = new MineFragment();
        Bundle bundle = new Bundle();
        bundle.putString(MainActivity.FRAGMENT_NAME, name);
        mineFragment.setArguments(bundle);
        return mineFragment;
    }

    /**
     * 呈现给用户最美好的一面
     * 通俗来讲，叫创建View
     *
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.clazz_practice_fragment, container, false);
        tvName = inflate.findViewById(R.id.tv_content_clazz_practice_fragment);
        return inflate;
    }

    /**
     * 初始化数据,例如网络请求
     *
     * @param savedInstanceState
     */
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Bundle arguments = getArguments();
        if (arguments != null) {
            String name = arguments.getString(MainActivity.FRAGMENT_NAME);
            tvName.setText(name);
        }
    }
}
